import cv2 as cv
import numpy as np

def showImg(x):
    global threshImg
    #erodeImg = cv.erode(threshImg, kernel, iterations =x)  # 腐蚀
    #cv.imshow('imgWin', erodeImg)
    dilateImg = cv.dilate(threshImg, kernel, iterations =x) # 膨胀
    cv.imshow('imgWin', dilateImg)

img = cv.imread("assets/book.jpg", 0)
cv.imshow('imgWin', img)

ret, threshImg = cv.threshold(img, 158, 255, cv.THRESH_BINARY)
cv.imshow('imgWin', threshImg)

kernel = cv.getStructuringElement(cv.MORPH_RECT,(3, 3))
# 创建滑块,注册拖动时的回调函数 showImg
cv.createTrackbar('slider', 'imgWin', 0, 20, showImg)

cv.waitKey(0)
